﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class TranslateInterfaceTranslated : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");
            else
            {
                GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
                OnlineUser ou = (OnlineUser)Session["User"];
                if (ou.UserAccessLevel == "1" || ou.UserAccessLevel == "0")
                {
                    Response.Redirect("~/GeneralMessage.aspx?MessageString=" + ou.UserAccessLevel);
                }
                
                if (ou.TeamId == "Null")
                    Response.Redirect("~/GeneralMessage.aspx?MessageString=274ggdizz5!lk");

                string Language = GND.ReadNivdalIntData("UserId", "Nivdal_GetUserTranslateLanguage", ou.UserId);
                if ((Language == null) || (Language == "0"))
                    Response.Redirect("GeneralMessage.aspx?MessageString=k882m299nnqmhtsd");
                else if (Language == "2")
                    Response.Redirect("TranslateEnglish.aspx");
                else
                {
                    this.LanguageHiddenField.Value = Language;
                    if (!IsPostBack)
                    {
                        this.TranslatedSentencesDataSource.SelectParameters.Add("Language", LanguageHiddenField.Value);
                        this.TranslatedSentencesDataSource.SelectParameters.Add("Page", " All pages");
                        this.IgnoredSentencesDataSource.SelectParameters.Add("UserId", ou.UserId);
                    }
                }
                IgnoredSentencesUpdatePanel.Visible = (IgnoredSentencesGridView.Rows.Count > 0);
            }
        }

        protected void RefreshData(object sender, EventArgs e)
        {
            this.TranslatedSentencesDataSource.SelectParameters.Clear();
            this.TranslatedSentencesDataSource.SelectParameters.Add("Language", LanguageHiddenField.Value);
            this.TranslatedSentencesDataSource.SelectParameters.Add("Page", PagesDDL.SelectedValue);

            SentencesGridView.DataBind();
        }

        protected void UnignoreResource(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Unignore")
            {
                GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
                GND.ReadNivdalStringData("IgnoreId", "Nivdal_UnignoreInterfaceSentence", e.CommandArgument);
                IgnoredSentencesGridView.DataBind();
            }
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}